﻿Imports System.Text
Imports System.Threading.Tasks

Public Class frmStartCompleteAutoPlateCheck
    Private objAP As New clsAutoPlantingDB
    Private Const UpSet As Integer = -1 '上调
    Private Const DownSet As Integer = 1 '下调
    Private base As New frmStartCompleteBase
    Private IcTag As New frmStartCompleteBase.TagData
    Private WG_IcTag As New frmStartCompleteBase.TagData
    Private EQUIP_IP As String = "127.0.0.1"
    Private PLT_EQUIP_NO As String = "P102"
    Private EQUIP_PORT As String = "3400"
    Private objDbLotDefect As New clsDbLotDefect
    Private clientStr As String
    Protected m_cEquipMat As New clsDbEquipMat
    Private m_dtHeader As DataTable
    Public Const DATE_TIME_FORMAT_DB As String = "yyyy/MM/dd HH:mm:ss"
    Private Sub frmStartCompleteAutoPlateCheck_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim objUserLogin As New clsLoginUser
        Dim UserNo As String = ""
        lblEquipID.Text = g_CURRENT_EQUIP_ID
        '得到设备IP等信息
        getEquipInfo()
        objAP.PLT_EQUIP_NO = PLT_EQUIP_NO
        g_EQUIP_NO = PLT_EQUIP_NO
        clientStr = GetBsiteClientString("A121")

        UserNo = objUserLogin.getUserNo(g_CURRENT_EQUIP_ID)
        txtOptNoStt.Text = UserNo
        txtOptNoEnd.Text = txtOptNoStt.Text

        '设置画面DataGridView
        setDataGridView()

        equipStartTimer.Interval = 2000

        m_cEquipCommandControl = New clsEquipCooperateCommand(EQUIP_IP, EQUIP_PORT)

        '设置提示内容
        If m_cEquipCommandControl.IsSetting() Then
            m_cEquipCommandControl.CommandConnect()
            lblLink.Text = "设备连接中》》》"
            Dim strCS As String = "CS"
            PutLog(Me.ToString, "CommandSend", strCS)
            m_cEquipCommandControl.CommandSend(strCS)
        End If
        setCheckInfo("Bsite同步中...")
        pnlCheckInfo.Refresh()

        Dim bsiteAsync As Threading.Thread
        bsiteAsync = New Threading.Thread(AddressOf getViewLotService)
        bsiteAsync.Start()


    End Sub
    Delegate Sub bsiteAsyncOver()
    Dim bao As New bsiteAsyncOver(AddressOf setbsiteAsyncOver)
    Sub setbsiteAsyncOver()
        pnlCheckInfo.Visible = False
    End Sub
    Public Sub getViewLotService()


        ViewMachineService_GetInf(PLT_EQUIP_NO, "A121")
        Me.Invoke(bao)
    End Sub

    Private Sub setDataGridView()
        dgv.DataSource = objAP.getWorkList

        For i As Integer = 0 To dgv.Columns.Count - 1
            dgv.Columns(i).SortMode = DataGridViewColumnSortMode.NotSortable
        Next
        For i As Integer = 0 To dgv.Rows.Count - 1
            If dgv.Rows(i).Cells("colType").Value = "着工中" Then
                dgv.Rows(i).DefaultCellStyle.BackColor = Color.Chartreuse
            End If
        Next
        Me.Refresh()
    End Sub

    Private Sub getEquipInfo()
        Dim _dt As DataTable = objAP.getEquipInfo(g_CURRENT_EQUIP_ID)
        If IsNothing(_dt) = False AndAlso _dt.Rows.Count > 0 Then
            EQUIP_IP = _dt.Rows(0)("ip_address")
            PLT_EQUIP_NO = _dt.Rows(0)("PLT_EQUIP_NO")
            EQUIP_PORT = _dt.Rows(0)("PORT_NO")
        End If
    End Sub
    Private Sub btnUP_Click(sender As Object, e As EventArgs) Handles btnUP.Click
        setUpDown(UpSet)
    End Sub

    ''' <summary>
    ''' UP、Down
    ''' </summary>
    ''' <param name="flg">-1：上调，1：下调</param>
    Private Sub setUpDown(flg As Integer)
        If dgv.SelectedRows.Count < 1 Then Exit Sub

        If MsgBox(getMsgStr("MSG10064", IIf(flg = UpSet, "上调", "下调")), MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
            Dim lot1 As String = dgv.SelectedRows(0).Cells("LOT_NO").Value
            Dim ut1 As String = dgv.SelectedRows(0).Cells("colUPDATE_TIME").Value
            Dim lot2 As String = ""
            Dim ut2 As String = ""
            Dim intSelectRowIndex As Integer = dgv.SelectedRows(0).Index

            If flg = UpSet Then
                If intSelectRowIndex <> 0 Then
                    lot2 = dgv.Rows(dgv.SelectedRows(0).Index + flg).Cells("LOT_NO").Value
                    ut2 = dgv.Rows(dgv.SelectedRows(0).Index + flg).Cells("colUPDATE_TIME").Value
                End If
            Else
                If intSelectRowIndex < dgv.Rows.Count - 1 Then
                    lot2 = dgv.Rows(dgv.SelectedRows(0).Index + flg).Cells("LOT_NO").Value
                    ut2 = dgv.Rows(dgv.SelectedRows(0).Index + flg).Cells("colUPDATE_TIME").Value
                End If
            End If

            If lot2 <> "" Then
                If objAP.changeUpdateTime(lot1, ut1, lot2, ut2) = 1 Then

                    setDataGridView()
                    dgv.Rows(intSelectRowIndex).Selected = False
                    dgv.Rows(intSelectRowIndex + flg).Selected = True

                End If
            End If
        End If
    End Sub

    Private Sub btnDown_Click(sender As Object, e As EventArgs) Handles btnDown.Click
        setUpDown(DownSet)
    End Sub

#Region "装置連携コマンド通信　自動着完工"
    ''' <summary>
    ''' 結果報告コマンドの送信
    ''' </summary>
    ''' <param name="commandName">コマンド</param>
    ''' <param name="result">結果</param>
    Protected Function sendResponseCommand(ByVal commandName As String, ByVal result As String) As Boolean
        Dim sendCommand = createResponseCommandStr(commandName, result, g_CURRENT_EQUIP_ID)
        PutLog(Me.ToString, "sendCommand", sendCommand)
        Return m_cEquipCommandControl.CommandSend(sendCommand)

    End Function

    ' TCPクライアント用イベント
    Protected WithEvents m_cEquipCommandControl As clsEquipCooperateCommand
    Delegate Sub TCPCLEventDelegate(e As TCPListener.TCPEventArgs)
    ''' <summary>
    ''' イベント受信
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub TCPCLEvent(sender As System.Object, e As TCPListener.TCPEventArgs) Handles m_cEquipCommandControl.tcpevent
        Debug.WriteLine("TCPCLEvent in")
        Dim adrData As New TCPCLEventDelegate(AddressOf DoTCPCLEvent)
        Try
            Me.BeginInvoke(adrData, e)
        Catch ex As Exception
            MsgBox(getMsgStr("MSG00186"))
        End Try
    End Sub
    Private Sub DoTCPCLEvent(e As TCPListener.TCPEventArgs)
        HideCommandWaiting()
        ' 接続完了
        If e.eventType = TCPListener.TCPEventArgs.TcpEventType.Connect Then
            Debug.WriteLine("接続完了")
            MsgBox("接続完了")
        End If
        If e.eventType = TCPListener.TCPEventArgs.TcpEventType.Shutdown Then
            Debug.WriteLine("接続切断")
            MsgBox("接続切断")
        End If
        ' データ受信
        If e.eventType = TCPListener.TCPEventArgs.TcpEventType.Receive Then


            'MsgBox("データ受信") 'TODO:DEL
            Debug.WriteLine("データ受信")
            Dim receiveDataStr = Encoding.ASCII.GetString(e.receiveData, 0, e.receiveData.Count())
            Debug.WriteLine(receiveDataStr)
            PutLog(Me.ToString, "RECEIVEDATA", receiveDataStr)

            ' 受信コマンド解析
            CommandReceive(receiveDataStr)

        End If
        ' Exception
        If e.eventType = TCPListener.TCPEventArgs.TcpEventType.Exception Then
            lblLink.Text = "设备连接失败！"
            lblLink.ForeColor = Color.Red

            Debug.WriteLine("Exception受信")
            Debug.WriteLine(e.exception.Message)
            CommandReceive(Nothing)
        End If
        If e.eventType = TCPListener.TCPEventArgs.TcpEventType.Timeout Then
            lblLink.Text = "设备连接失败！连接超时！"
            lblLink.ForeColor = Color.Red

            Debug.WriteLine("timeout受信")
            CommandReceive(Nothing)
        End If
        If e.eventType = TCPListener.TCPEventArgs.TcpEventType.Cancel Then
            lblLink.Text = "设备连接失败！"
            lblLink.ForeColor = Color.Red

            Debug.WriteLine("Cancel受信")
            CommandReceive(Nothing)
        End If
        If e.eventType = TCPListener.TCPEventArgs.TcpEventType.Retry Then
            Debug.WriteLine("retry受信")
            m_cEquipCommandControl.CommandConnect()
        End If
    End Sub
#End Region

#Region "自動着完工　ほかの処理"
    ''' <summary>
    ''' コマンド受信
    ''' 受信コマンドの解析結果を各画面に渡す
    ''' </summary>
    ''' <param name="receiveData">受信コマンド</param>
    Private Sub CommandReceive(receiveData As String)

        'MsgBox("Baseクラスの「CommandReceive」メソッドに入った！")
        HideCommandWaiting()
        If IsNothing(receiveData) Then
            Exit Sub
        End If
        Dim _id As String = receiveData.Substring(0, 2)

        If _id = "JG" Then
            setLinkOk()
        End If

        If _id = "ZG" Then '设备->SF的料盒信息
            setLinkOk()
            startBefore(commandAnalyseZG(receiveData))
        ElseIf _id = "ZR" Then 'SF->设备的可否着工反馈
            setLinkOk()
            startWork(commandAnalyseZR(receiveData))
        ElseIf _id = "ZW" Then '设备是否着工成功
            setLinkOk()
            startWorkEnd(commandAnalyseZW(receiveData))
        ElseIf _id = "WW" Then '处理中发生设备错误
            setLinkOk()
            equipError(commandAnalyseWW(receiveData))
        ElseIf _id = "WG" Then '完工处理
            setLinkOk()
            finishWork(commandAnalyseWG(receiveData))
        End If
    End Sub

    Private Sub setLinkOk()

        lblLink.Text = "设备连接成功！"
        lblLink.ForeColor = Color.Green
    End Sub

#Region "ZG相关"

    Private Sub startBefore(objZG As cmd_ZG)
        Dim objZN As New cmd_ZN
        Dim strZN As String = ""

        '根据料盒号找到LotNo
        IcTag.szLotNo = objDbLotDefect.GetLotNoByRack(objZG.rackNo)

        If IcTag.szLotNo = "" Then
            setCheckInfo(getMsgStr("MSG00007", "料盒号：" & objZG.rackNo & " 对应的组立Key No."))
            Exit Sub
        End If
        setDgvSelectedRow(objZG.rackNo)
        '同步bSite的Lot信息后，创建ZN指令
        If SyncLotInfoBsite(IcTag.szLotNo, objZG.rackNo, IcTag) = 0 Then

            With objZN
                .ID = "ZN"
                .inputNum = IcTag.iInput
                .OKnum = .inputNum
                .NGnum = 0
                .FrameNum = IcTag.iFrame
                .ProcCD = IcTag.szProcsCD
                .Status = getFlg(IcTag.szLotNo)
                .PKG = getPKG(IcTag.szLotNo)
            End With

            strZN = CreateZN(objZN)

            m_cEquipCommandControl.CommandSend(strZN)
        End If

    End Sub


    Private Function getFlg(_lot As String) As String
        Dim dt As DataTable = dgv.DataSource
        Dim strType As String = 0

        Dim dr As DataRow() = dt.Select("LOT_NO='" & _lot & "'")
        If dr.Length > 0 Then

            For i As Integer = 0 To dr(0)("CHANGE_STATUS").ToString.Length - 1
                If dr(0)("CHANGE_STATUS").ToString.Substring(i, 1) = 1 Then
                    strType = 1
                    Exit For
                End If
            Next

        End If
        Return strType
    End Function
    Private Function getPKG(_lot As String) As String
        Dim dt As DataTable = dgv.DataSource
        Dim strPKG As String = ""

        Dim dr As DataRow() = dt.Select("LOT_NO='" & _lot & "'")
        If dr.Length > 0 Then
            strPKG = dr(0)("PKG_NO").ToString
        End If
        Return strPKG
    End Function
    ''' <summary>
    ''' bSite同步
    ''' </summary>
    ''' <param name="_lotNo">组立keyNo.</param>
    ''' <param name="_rackNo">料盒号</param>
    ''' <param name="_ictag">ictag对象</param>
    ''' <returns>0：成功，1：失败</returns>
    Private Function SyncLotInfoBsite(_lotNo As String, _rackNo As String, ByRef _ictag As frmStartCompleteBase.TagData) As Integer
        setCheckInfo("Bsite同步中...")
        pnlCheckInfo.Refresh()
        Dim m_cLotInfo As New clsDbLotInfo

        Dim param As InSiteWebService.InViewLot = New InSiteWebService.InViewLot()

        param.Name = _lotNo
        '<<20171012_1 兪
        _ictag.szLotNo = _lotNo

        Dim viewLotServiceInfo As InSiteWebService.OutLotStd = mdl_ViewLotService.ViewLotServiceGet(param, clientStr)
        If Not IsNothing(viewLotServiceInfo) AndAlso STS_SUCCESS.Equals(viewLotServiceInfo.Header.Status) Then
            With viewLotServiceInfo
                _ictag.szProcsCD = .LotInf.Operation

                If .LotInf.InProcess Then

                    If _ictag.Status = frmStartCompleteBase.TagProcessStatus.Ready Then
                        _ictag.Status = frmStartCompleteBase.TagProcessStatus.Processing
                    End If

                Else
                    If _ictag.Status <> frmStartCompleteBase.TagProcessStatus.Ready Then
                        _ictag.Status = frmStartCompleteBase.TagProcessStatus.Ready
                    End If
                End If

                If .LotInf.Machine.Length > 0 AndAlso .LotInf.Machine(0) <> "" Then
                    _ictag.szEquipID = .LotInf.Machine(0)
                End If

                If IsNumeric(.LotInf.Qty) Then
                    _ictag.iInput = CInt(.LotInf.Qty)
                    _ictag.iFinish = CInt(.LotInf.Qty)
                End If
                'ADD 苗 2018/2/6 BEGIN
                If IsNumeric(.LotInf.Qty2) Then
                    _ictag.iFrame = CInt(.LotInf.Qty2)
                    '>>20180302 大賀 GroupKey入力時ウェハ枚数入力

                End If
                'ADD 苗 2018/2/6 END
                If .LotInf.IsOnHold Then
                    _ictag.OnHoldSt = frmStartCompleteBase.OnHoldStatus.OnHold
                Else
                    _ictag.OnHoldSt = frmStartCompleteBase.OnHoldStatus.Normal
                End If
                _ictag.container1 = _rackNo
            End With

            Dim m_cData As New clsDbCondData
            Dim dtData = m_cData.GetWbLotData(_lotNo)
            If dtData.Rows.Count > 0 Then
                '×印数
                _ictag.iCross = base.DBNullTOblank(dtData.Rows(0)("BADMARKNUM")) 'UPD 苗 2018/10/23
                '×印枚数
                _ictag.iCrossFrm = base.DBNullTOblank(dtData.Rows(0)("badmark_framenum")) 'UPD 苗 2018/10/23
            End If

            'setICtagByFrameInfo()
            m_cLotInfo.SaveTagLotInfo(_ictag, 0)

            '将icTag设置到画面上
            setLotInfoToForm(_ictag, _rackNo)
            Me.pnlCheckInfo.Visible = False
            Return 0
        Else
            Me.pnlCheckInfo.Visible = False
            Return 1
            '<<20171202 兪
        End If

    End Function

    Private Function CreateZN(ByVal objzn As cmd_ZN) As String

        With objzn
            .inputNum = .inputNum.PadRight(5, " ")
            .OKnum = .OKnum.PadRight(5, " ")
            .NGnum = .NGnum.PadRight(5, " ")
            .FrameNum = .FrameNum.PadRight(3, " ")
            .ProcCD = .ProcCD.PadRight(4, " ")
            .PKG = .PKG.PadRight(30, " ")

            Return .ID & .inputNum & .OKnum & .NGnum & .FrameNum & .ProcCD & .PKG & .Status
        End With
    End Function
#End Region

#Region "ZR相关"
    Private Sub startWork(objZR As cmd_ZR)


        '判断是否是ZG发来的料盒
        If objZR.rackNo <> IcTag.container1 Then
            setCheckInfo("ZR报文发送的料盒号:" & objZR.rackNo & "与ZG报文发来的料盒不同！")
            Exit Sub
        End If
        '判断结果
        If objZR.result.ToUpper = NG Then
            'TODO:NG番号
            setCheckInfo("设备着工准备NG！")
            Exit Sub
        End If
        setDgvSelectedRow(objZR.rackNo)
        'bSite着工
        Dim inputBsite As New InSiteWebService.InMoveIn
        Dim outputBsite As New InSiteWebService.OutMoveIn
        Dim outHeader As InSiteWebService.OutHeader
        If txtOptNoStt.Text = "" Then txtOptNoStt.Text = "INSITEADMIN"
        inputBsite.Employee = txtOptNoStt.Text    '開始作業者
        inputBsite.Lot = IcTag.szLotNo.Trim       'ロットNo
        inputBsite.Machine = lblEquipID.Text      '装置No
        inputBsite.IgnoreLimitTime = True   '強制着工
        'inputBsite.MoveInForWaferLot = moveInWaferLot   '拡散ロット着工
        'If Not String.IsNullOrEmpty(outWeekCode) Then
        '    inputBsite.WeeklyCode = outWeekCode '週コード
        'End If

        outputBsite = MoveInService_Execute(inputBsite, clientStr)
        '戻り情報を保持
        outHeader = outputBsite.Header
        Dim _zjResult As String = NG
        'bsite着工成功
        If STS_SUCCESS.Equals(outHeader.Status) Then
            _zjResult = OK
        End If
        '反馈ZJ报文至设备
        sendZJ(_zjResult)

        '列表更新
        setDataGridView()
    End Sub

    Public Sub sendZJ(_result As String)
        Dim strZJ As String = "ZJ" & IcTag.container1.PadRight(6, " ") & _result
        PutLog(Me.ToString, "CommandSend", strZJ)
        m_cEquipCommandControl.CommandSend(strZJ)
    End Sub
#End Region

#Region "ZW相关"
    Private Sub startWorkEnd(objZW As cmd_ZW)
        '判断是否是ZG发来的料盒
        If objZW.rackNo <> IcTag.container1 Then
            setCheckInfo("ZW报文发送的料盒号:" & objZW.rackNo & "与ZG报文发来的料盒不同！")
            Exit Sub
        End If
        If objZW.result.ToUpper = NG Then
            'TODO:NG番号
            setCheckInfo("设备着工失败！" & vbCrLf & "组立key No.:" & IcTag.szLotNo & " 料盒号：" & objZW.rackNo)
            Exit Sub
        End If
        setDgvSelectedRow(objZW.rackNo)
        '得到当前Lot的着工Lot工程
        Dim _prodCD = getProdCD(IcTag.szLotNo)
        IcTag.szProcsCD = _prodCD
        '更新数据库
        setHeader(1, Now, IcTag)
        If objAP.workStart(IcTag.szLotNo, g_CURRENT_EQUIP_ID, _prodCD, m_dtHeader) = 1 Then
            equipStartTimer.Start()
            setBsiteInfo(True, "设备着工成功！" & vbCrLf & "组立key No.:" & IcTag.szLotNo & " 料盒号：" & objZW.rackNo)
            '-----------------------------------
            btnCancel.Enabled = True
            btnErrInput.Enabled = True
            btnTotalComp.Enabled = True
            '-----------------------------------
            SyncLotInfoBsite(IcTag.szLotNo, objZW.rackNo, IcTag)
        Else
            setBsiteInfo(False, "数据库着工信息保存失败！" & vbCrLf & "组立key No.:" & IcTag.szLotNo & " 料盒号：" & objZW.rackNo)
        End If
    End Sub

    ''' <summary>
    ''' 得到bSite中的工程号
    ''' </summary>
    ''' <param name="_lotNo">LotNo</param>
    ''' <returns>工程号</returns>
    Public Function getProdCD(_lotNo As String) As String
        Dim param As InSiteWebService.InViewLot = New InSiteWebService.InViewLot()

        param.Name = _lotNo
        '<<20171012_1 兪

        Dim viewLotServiceInfo As InSiteWebService.OutLotStd = mdl_ViewLotService.ViewLotServiceGet(param, clientStr)
        If Not IsNothing(viewLotServiceInfo) AndAlso STS_SUCCESS.Equals(viewLotServiceInfo.Header.Status) Then
            Return viewLotServiceInfo.LotInf.Operation
        Else
            Return "A121"
        End If

    End Function

#End Region

#Region "WW相关"
    Private Sub equipError(objWW As cmd_WW)
        '判断是否是ZG发来的料盒
        'If objWW.rackNo <> IcTag.container1 Then
        '    setCheckInfo("WW报文发送的料盒号:" & objWW.rackNo & "与ZG报文发来的料盒不同！")
        '    Exit Sub
        'End If

        '根据料盒号找到LotNo
        Dim _lotno As String = objDbLotDefect.GetLotNoByRack(objWW.rackNo)

        If _lotno = "" Then
            setCheckInfo(getMsgStr("MSG00007", "料盒号：" & objWW.rackNo & " 对应的组立Key No."))
            Exit Sub
        End If
        setDgvSelectedRow(objWW.rackNo)
        If objWW.result.ToUpper = NG Then
            'TODO:NG番号
            setCheckInfo("设备完工失败！" & vbCrLf & "组立key No.:" & _lotno & " 料盒号：" & objWW.rackNo)
            Exit Sub
        End If

    End Sub
#End Region

#Region "WG相关"
    Private Sub finishWork(objWG As cmd_WG)

        '完工作业者check
        If txtOptNoEnd.Text = "" Then
            setCheckInfo(getMsgStr("MSG00002", btnOptNoEnd.Text))
            txtOptNoEnd.Focus()
            Exit Sub
        End If

        '根据料盒号找到LotNo
        WG_IcTag.szLotNo = objDbLotDefect.GetLotNoByRack(objWG.rackNo)
        setDgvSelectedRow(objWG.rackNo)

        If WG_IcTag.szLotNo = "" Then
            setCheckInfo(getMsgStr("MSG00007", "料盒号：" & objWG.rackNo & " 对应的组立Key No."))
            Exit Sub
        End If

        '同步bSite的Lot信息后，创建WJ指令
        If SyncLotInfoBsite(WG_IcTag.szLotNo, objWG.rackNo, WG_IcTag) = 0 Then
            lblFailedCnt.Text = 0
            lblCompleteCnt.Text = CInt(lblInputCnt.Text)
            lblPcbCnt.Text = lblInputFrm.Text
            lblCrossCnt.Text = lblInputCross.Text
            lblCrossPcbCnt.Text = lblInputCrossFrm.Text
            If objWG.result.ToUpper = NG Then
                'TODO:NG番号
                setCheckInfo("设备完工有不良！" & vbCrLf &
                             "组立key No.:" & WG_IcTag.szLotNo &
                             "  料盒号：" & objWG.rackNo & vbCrLf &
                             getListItemNum(objWG))
                '不良内容保存
                objAP.saveError(objWG, WG_IcTag.szLotNo)
                Exit Sub
            End If
            'bSite完工
            Dim outHeader As InSiteWebService.OutHeader = MoveStd(WG_IcTag)
            If outHeader.Status.Equals(STS_SUCCESS) Then
                '查询bSite，得到次工程CD
                Dim _nextKouteiCD As String = ""
                _nextKouteiCD = getNextProdCD(WG_IcTag.szLotNo)

                '完工后进行数据库变更
                setHeader(3, Now, WG_IcTag)
                If objAP.finishWork(WG_IcTag.szLotNo, g_CURRENT_EQUIP_ID, WG_IcTag.szProcsCD, _nextKouteiCD, m_dtHeader) Then
                    sendWJ(objWG.rackNo, OK)
                    'ADD 苗 2018/1/7 END
                    btnStart.Text = getMsgStr("MSG00121")
                    btnStart.BackColor = Color.Cyan

                    equipStartTimer.Start()
                    setBsiteInfo(True, "设备完工成功！" & vbCrLf &
                                 "组立key No.:" & IcTag.szLotNo &
                                 "    料盒号：" & objWG.rackNo)
                    '-----------------------------------
                    btnCancel.Enabled = False
                    btnErrInput.Enabled = False
                    btnTotalComp.Enabled = False
                    '-----------------------------------
                    '列表更新
                    setDataGridView()
                Else
                    sendWJ(objWG.rackNo, NG)
                    setBsiteInfo(False, "数据库完工信息保存失败！" & vbCrLf &
                                 "组立key No.:" & IcTag.szLotNo &
                                 "  料盒号：" & objWG.rackNo)
                End If

            Else
                btnStart.Text = getMsgStr("MSG00123")
                btnStart.BackColor = Color.LightCoral

                sendWJ(objWG.rackNo, NG)
                setBsiteInfo(False, "bsite完工失败！" & vbCrLf &
                             "组立key No.:" & IcTag.szLotNo &
                             "  料盒号：" & objWG.rackNo & vbCrLf &
                             "  原因：" & outHeader.Message)

            End If

        End If

    End Sub



    Private Function getListItemNum(objWG As cmd_WG) As String
        Dim str As String = ""

        If objWG.PL1A1 <> 0 Then
            str &= vbTab & "框架变形 数量 : " & objWG.PL1A1 & vbCrLf
        End If
        If objWG.PL1B1 <> 0 Then
            str &= vbTab & "异物附着 数量 : " & objWG.PL1B1 & vbCrLf
        End If
        If objWG.PL1C1 <> 0 Then
            str &= vbTab & "电镀变色 数量 : " & objWG.PL1C1 & vbCrLf
        End If
        If objWG.PL1D1 <> 0 Then
            str &= vbTab & "电镀脏污 数量 : " & objWG.PL1D1 & vbCrLf
        End If
        If objWG.PL1E1 <> 0 Then
            str &= vbTab & "异常析出 数量 : " & objWG.PL1E1 & vbCrLf
        End If
        If objWG.PL1F1 <> 0 Then
            str &= vbTab & "电镀毛刺 数量 : " & objWG.PL1F1 & vbCrLf
        End If
        If objWG.PL1G1 <> 0 Then
            str &= vbTab & "溢料残留 数量 : " & objWG.PL1G1 & vbCrLf
        End If
        If objWG.PL1H1 <> 0 Then
            str &= vbTab & "未电镀 数量 : " & objWG.PL1H1 & vbCrLf
        End If
        If objWG.PL1I1 <> 0 Then
            str &= vbTab & "其他 数量 : " & objWG.PL1I1
        End If
        Return str
    End Function
    Private Function getNextProdCD(_lotNo As String) As String
        Dim param As InSiteWebService.InViewLot = New InSiteWebService.InViewLot()

        param.Name = _lotNo

        Dim viewLotServiceInfo As InSiteWebService.OutLotStd = mdl_ViewLotService.ViewLotServiceGet(param, clientStr)
        If Not IsNothing(viewLotServiceInfo) AndAlso STS_SUCCESS.Equals(viewLotServiceInfo.Header.Status) Then
            Return viewLotServiceInfo.LotInf.NextOperation
        Else
            Return ""
        End If
    End Function

    Private Sub sendWJ(_rackNo As String, _result As String)
        Dim strWJ As String = "WJ" & _rackNo
        PutLog(Me.ToString, "CommandSend", strWJ)
        m_cEquipCommandControl.CommandSend(strWJ)
    End Sub

    ''' <summary>
    ''' bsite完工
    ''' </summary>
    ''' <param name="_wg">ictag对象</param>
    ''' <returns>bsite完工信息</returns>
    Private Function MoveStd(_wg As frmStartCompleteBase.TagData) As InSiteWebService.OutHeader
        Dim lossInf() As InSiteWebService.LossData = {}
        Dim inputBsiteStd As New InSiteWebService.InMoveStd
        Dim outputBsiteStd As New InSiteWebService.OutMoveStd
        Dim outHeader As InSiteWebService.OutHeader
        inputBsiteStd.Employee = txtOptNoEnd.Text  '終了作業者
        inputBsiteStd.Lot = _wg.szLotNo.Trim       'ロットNo
        inputBsiteStd.Machine = lblEquipID.Text    '装置No
        inputBsiteStd.IgnoreWarning = True    '強制着工
        inputBsiteStd.LossInf = lossInf       '不良数 

        inputBsiteStd.Qty = _wg.iInput      '投入数
        inputBsiteStd.Qty2 = _wg.iFrame     'フレーム枚数’ADD 苗　2018/1/17

        outputBsiteStd = MoveStdService_Execute(inputBsiteStd, clientStr)
        '戻り情報を保持
        outHeader = outputBsiteStd.Header
        Return outHeader

    End Function
#End Region

#Region "Command信息分析"
    Private Function commandAnalyseZG(_receiveData As String) As cmd_ZG
        Dim obj As New cmd_ZG
        obj.ID = _receiveData.Substring(0, 2)
        obj.rackNo = _receiveData.Substring(2, 6).Trim
        Return obj
    End Function
    Private Function commandAnalyseZR(_receiveData As String) As cmd_ZR
        Dim obj As New cmd_ZR
        obj.ID = _receiveData.Substring(0, 2)
        obj.rackNo = _receiveData.Substring(2, 6).Trim
        obj.result = _receiveData.Substring(8, 2)
        obj.errorNo = _receiveData.Substring(10, 2)
        Return obj
    End Function
    Private Function commandAnalyseZW(_receiveData As String) As cmd_ZW
        Dim obj As New cmd_ZW
        obj.ID = _receiveData.Substring(0, 2)
        obj.rackNo = _receiveData.Substring(2, 6).Trim
        obj.result = _receiveData.Substring(8, 2)
        obj.errorNo = _receiveData.Substring(10, 2)
        Return obj
    End Function
    Private Function commandAnalyseWG(_receiveData As String) As cmd_WG
        Dim obj As New cmd_WG
        With obj
            .ID = _receiveData.Substring(0, 2)
            .rackNo = _receiveData.Substring(2, 6).Trim
            .result = _receiveData.Substring(8, 2)
            .PL1A1 = CInt(IIf(_receiveData.Substring(10, 5).Trim = "", 0, _receiveData.Substring(10, 5).Trim))
            .PL1B1 = CInt(IIf(_receiveData.Substring(15, 5).Trim = "", 0, _receiveData.Substring(15, 5).Trim))
            .PL1C1 = CInt(IIf(_receiveData.Substring(20, 5).Trim = "", 0, _receiveData.Substring(20, 5).Trim))
            .PL1D1 = CInt(IIf(_receiveData.Substring(25, 5).Trim = "", 0, _receiveData.Substring(25, 5).Trim))
            .PL1E1 = CInt(IIf(_receiveData.Substring(30, 5).Trim = "", 0, _receiveData.Substring(30, 5).Trim))
            .PL1F1 = CInt(IIf(_receiveData.Substring(35, 5).Trim = "", 0, _receiveData.Substring(35, 5).Trim))
            .PL1G1 = CInt(IIf(_receiveData.Substring(40, 5).Trim = "", 0, _receiveData.Substring(40, 5).Trim))
            .PL1H1 = CInt(IIf(_receiveData.Substring(45, 5).Trim = "", 0, _receiveData.Substring(45, 5).Trim))
            .PL1I1 = CInt(IIf(_receiveData.Substring(50, 5).Trim = "", 0, _receiveData.Substring(50, 5).Trim))
        End With

        Return obj
    End Function

    Private Function commandAnalyseWW(_receiveData As String) As cmd_WW
        Dim obj As New cmd_WW
        obj.ID = _receiveData.Substring(0, 2)
        obj.rackNo = _receiveData.Substring(2, 6).Trim
        obj.result = _receiveData.Substring(8, 2)
        obj.errorNo = _receiveData.Substring(10, 2)
        Return obj
    End Function

#End Region

    ''' <summary>
    ''' 得到Lot的制造条件 
    ''' </summary>
    ''' <param name="_ic">ictag对象</param>
    ''' <param name="_rackNo">料盒号</param>
    Private Sub setLotInfoToForm(_ic As frmStartCompleteBase.TagData, _rackNo As String)
        With _ic
            txtLotNo.Text = .szLotNo
            txtDiffLot.Text = .szDifLotNo

            '从制造条件中得到
            Dim dtJyokenData = New DataTable
            Dim m_cData As New clsDbCondData
            dtJyokenData = m_cData.GetJyokenData(.szLotNo, .szProcsCD)
            For Each drJyoken In dtJyokenData.Rows
                If drJyoken("KOTEI").Equals("LOTINFO") Then
                    If drJyoken("KOMOKUNAME").Equals("PRODUCT NAME") Then
                        lblkindNm.Text = drJyoken("KOMOKUDATA")
                    ElseIf drJyoken("KOMOKUNAME").Equals("PB LAYOUT") Then
                        lblPbLayout.Text = drJyoken("KOMOKUDATA")
                    ElseIf drJyoken("KOMOKUNAME").Equals("SHAPE") Then
                        lblShape.Text = drJyoken("KOMOKUDATA")
                    ElseIf drJyoken("KOMOKUNAME").Equals("WAFER LOTNO") Then
                        lblWaferKeyNo.Text = drJyoken("KOMOKUDATA").ToString
                    End If
                End If

            Next
            lblBeginTime.Text = String.Empty
            lblEndTime.Text = String.Empty

            lblInputCnt.Text = .iInput
            lblInputFrm.Text = .iFrame
            lblInputCross.Text = .iCross
            lblInputCrossFrm.Text = .iCrossFrm
            lblProcCD.Text = .szProcsCD

            lblCompleteCnt.Text = String.Empty
            lblPcbCnt.Text = String.Empty
            lblCrossCnt.Text = String.Empty
            lblCrossPcbCnt.Text = String.Empty
            lblFailedCnt.Text = String.Empty
            lblRackNo.Text = _rackNo

            If .Status = frmStartCompleteBase.TagProcessStatus.Ready Then
                btnStart.Text = getMsgStr("MSG00118")
                btnStart.BackColor = Drawing.SystemColors.Control
                '-----------------------------------
                btnCancel.Enabled = False
                btnErrInput.Enabled = False
                btnTotalComp.Enabled = False
                '-----------------------------------
            ElseIf .Status = frmStartCompleteBase.TagProcessStatus.Processing Then
                btnStart.Text = getMsgStr("MSG00119")
                btnStart.BackColor = Color.Lime
                '-----------------------------------
                btnCancel.Enabled = True
                btnErrInput.Enabled = True
                btnTotalComp.Enabled = True
                '-----------------------------------
            End If

        End With

    End Sub
    Private Sub clearForm()
        txtLotNo.Text = String.Empty
        txtDiffLot.Text = String.Empty
        lblWaferKeyNo.Text = String.Empty
        lblPbLayout.Text = String.Empty
        lblShape.Text = String.Empty

        lblBeginTime.Text = String.Empty
        lblEndTime.Text = String.Empty
        lblkindNm.Text = String.Empty
        lblInputCnt.Text = String.Empty
        lblInputFrm.Text = String.Empty
        lblInputCross.Text = String.Empty
        lblInputCrossFrm.Text = String.Empty
        lblCompleteCnt.Text = String.Empty
        lblPcbCnt.Text = String.Empty
        lblCrossCnt.Text = String.Empty
        lblCrossPcbCnt.Text = String.Empty
        lblFailedCnt.Text = String.Empty
        lblRackNo.Text = String.Empty
        lblProcCD.Text = String.Empty

        btnStart.Text = getMsgStr("MSG00118")
        btnStart.BackColor = Drawing.SystemColors.Control
    End Sub

    Public Function GetBsiteClientString(_procCD As String) As String
        Dim m_cEquipMat As New clsDbEquipMat
        Dim retStr = m_cEquipMat.GetBsiteClientString(_procCD)
        Return retStr
    End Function
    Public Sub PutLog(ByVal szSender As String, ByVal szOperator As String, ByVal szMsg As String, Optional ByVal _lotNo As String = "")
        Dim logRecord As frmStartCompleteBase.Log

        With logRecord
            .szEquipID = lblEquipID.Text 'UPD 苗 2018/1/19 装置No.の対応
            .szProcCD = "A121"
            .szLotNo = _lotNo
            .dteOpt = DateTime.Now
            .szOperator = szOperator
            .szControl = szSender.Replace(",", "")
            .szMsg = szMsg
        End With
        base.PutDbLog(logRecord)
    End Sub
    Protected Sub HideCommandWaiting()
        Me.Cursor = Cursors.Default

        Me.Enabled = True
    End Sub

    Private Sub setDgvSelectedRow(_rackNo As String)
        For i As Integer = 0 To dgv.Rows.Count - 1
            If dgv.Rows(i).Cells(1).Value.ToString.ToUpper = _rackNo.ToUpper Then
                dgv.Rows(i).Selected = True
                Exit For
            End If
        Next
    End Sub
#End Region

#Region "警告画面"

    Private Sub setCheckInfo(str As String)
        Me.pnlCheckInfo.Visible = True
        Me.pnlCheckInfo.BringToFront()
        Me.pnlCheckInfo.BackColor = Color.Yellow
        txtChkInfo.BackColor = Color.Yellow

        If txtChkInfo.Text.Contains(str) Then Exit Sub

        txtChkInfo.Text = str & vbCrLf
        txtChkInfo.ForeColor = Color.Black
    End Sub
    Dim WithEvents equipStartTimer As New Timer
    Private Sub equipStartTimer_Tick(sender As Object, e As EventArgs) Handles equipStartTimer.Tick
        pnlCheckInfo.Visible = False
        equipStartTimer.Stop()
    End Sub
    Private Sub setBsiteInfo(_result As Boolean, str As String)

        Me.pnlCheckInfo.Visible = True
        Me.pnlCheckInfo.BringToFront()
        If _result = True Then
            '绿底白字
            txtChkInfo.ForeColor = Color.White
            txtChkInfo.BackColor = Color.Green
        Else
            '黄底黑字
            txtChkInfo.ForeColor = Color.Black
            txtChkInfo.BackColor = Color.Yellow
        End If
        If txtChkInfo.Text.Contains(str) Then Exit Sub

        txtChkInfo.Text = str & vbCrLf
    End Sub

    Private Sub btnTotalComp_Click(sender As Object, e As EventArgs) Handles btnTotalComp.Click
        Dim dtErr As DataTable
        Dim objLotDefect As New clsDbLotDefect
        Dim lossInf() As InSiteWebService.LossData = {}
        Dim outHeader As InSiteWebService.OutHeader
        Dim LossQtySum As Integer = 0
        dtErr = objLotDefect.GetDefectData(txtLotNo.Text, g_CURRENT_EQUIP_ID, lblProcCD.Text)

        If Not (IsNothing(dtErr) OrElse dtErr.Rows.Count <= 0) Then

            ReDim lossInf(dtErr.Rows.Count - 1)
            For i = 1 To dtErr.Rows.Count

                'b-Site不良数セット
                lossInf(i - 1) = New InSiteWebService.LossData
                lossInf(i - 1).LossReason = dtErr.Rows(i - 1)(0)
                lossInf(i - 1).LossQty = dtErr(i - 1)(2)
                LossQtySum += CInt(lossInf(i - 1).LossQty) 'ADD 苗 2018/2/3
            Next
        End If
        Dim inputBsite As New InSiteWebService.InMoveStd
        Dim outputBsite As New InSiteWebService.OutMoveStd
        inputBsite.Employee = IIf(txtOptNoEnd.Text = "", txtOptNoStt.Text, txtOptNoEnd.Text) '終了作業者
        inputBsite.Lot = txtLotNo.Text.Trim       'ロットNo
        inputBsite.Machine = g_CURRENT_EQUIP_ID         '装置No
        inputBsite.IgnoreWarning = True    '強制着工

        inputBsite.LossInf = lossInf            '不良数
        'inputBsite.Qty = lblCompleteCnt.Text    '完成数
        'UPD 苗 2018/2/3 BEGIN
        If LossQtySum = 0 Then
            inputBsite.Qty = lblInputCnt.Text     '投入数
        Else
            inputBsite.Qty = CInt(lblInputCnt.Text) - LossQtySum    '完成数
        End If

        inputBsite.Qty2 = lblInputFrm.Text 'フレーム枚数’ADD 苗　2018/1/17

        outputBsite = MoveStdService_Execute(inputBsite, clientStr)
        '戻り情報を保持
        outHeader = outputBsite.Header

        If outHeader.Status.Equals(STS_SUCCESS) Then
            '查询bSite，得到次工程CD
            Dim _nextKouteiCD As String = ""
            _nextKouteiCD = getNextProdCD(WG_IcTag.szLotNo)

            '完工后进行数据库变更
            setHeader(3, Now, WG_IcTag)
            If objAP.finishWork(WG_IcTag.szLotNo, g_CURRENT_EQUIP_ID, WG_IcTag.szProcsCD, _nextKouteiCD, m_dtHeader) Then
                sendWJ(lblRackNo.Text, OK)
                'ADD 苗 2018/1/7 END
                btnStart.Text = getMsgStr("MSG00121")
                btnStart.BackColor = Color.Cyan

                equipStartTimer.Start()
                setBsiteInfo(True, "设备完工成功！" & vbCrLf &
                             "组立key No.:" & IcTag.szLotNo &
                             "    料盒号：" & lblRackNo.Text)
                '-----------------------------------
                btnCancel.Enabled = False
                btnErrInput.Enabled = False
                btnTotalComp.Enabled = False
                '-----------------------------------
                '列表更新
                setDataGridView()
            Else
                sendWJ(lblRackNo.Text, NG)
                setBsiteInfo(False, "数据库完工信息保存失败！" & vbCrLf &
                             "组立key No.:" & IcTag.szLotNo &
                             "  料盒号：" & lblRackNo.Text)
            End If

        Else
            btnStart.Text = getMsgStr("MSG00123")
            btnStart.BackColor = Color.LightCoral

            sendWJ(lblRackNo.Text, NG)
            setBsiteInfo(False, "bsite完工失败！" & vbCrLf &
                         "组立key No.:" & IcTag.szLotNo &
                         "  料盒号：" & lblRackNo.Text & vbCrLf &
                         "  原因：" & outHeader.Message)

        End If
    End Sub

    Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
        If txtLotNo.Text = String.Empty Then Exit Sub
        If btnStart.Text = getMsgStr("MSG00118") Then Exit Sub
        Dim outHeader As InSiteWebService.OutHeader
        '着工取消确认msg
        If MsgBox(getMsgStr("MSG10021"), MsgBoxStyle.YesNo) = MsgBoxResult.No Then
            Exit Sub
        End If

        Dim inputBsite As New InSiteWebService.InMoveInCancel
        Dim outputBsite As New InSiteWebService.OutMoveInCancel
        inputBsite.Employee = txtOptNoStt.Text
        inputBsite.Lot = txtLotNo.Text
        inputBsite.Machine = g_CURRENT_EQUIP_ID         '装置No
        outHeader = Nothing

        outputBsite = MoveInCancelService_Execute(inputBsite, clientStr)
        '戻り情報を保持
        outHeader = outputBsite.Header

        If outHeader.Status.Equals(STS_SUCCESS) Then

            btnStart.Text = getMsgStr("MSG00122")
            btnStart.BackColor = Color.LightCoral

            '着工取消履历保存
            If IcTag.szLotNo = txtLotNo.Text Then
                setHeader(9, Now, IcTag)
                Dim i As Integer
                m_cEquipMat.SaveHeader(m_dtHeader, i, txtLotNo.Text, lblEquipID.Text, 9, Now)
            ElseIf WG_IcTag.szLotNo = txtLotNo.Text Then
                setHeader(9, Now, WG_IcTag)
                Dim i As Integer
                m_cEquipMat.SaveHeader(m_dtHeader, i, txtLotNo.Text, lblEquipID.Text, 9, Now)
            End If

            objAP.WorkCancel(txtLotNo.Text)

            equipStartTimer.Start()
            setBsiteInfo(True, "着工取消成功！" & vbCrLf &
                             "组立key No.:" & txtLotNo.Text &
                             "    料盒号：" & lblRackNo.Text)
            '列表更新
            setDataGridView()

        Else
            setBsiteInfo(False, "着工取消失败！" & vbCrLf &
                         "组立key No.:" & txtLotNo.Text &
                         "  料盒号：" & lblRackNo.Text & vbCrLf &
                         "原因：" & outHeader.Message)

        End If
    End Sub

    Private Sub btnUserExit_Click(sender As Object, e As EventArgs) Handles btnUserExit.Click
        txtUser.Text = ""
        Time_LoginUser.Start()
        pnlUserLogin.Visible = False
    End Sub

    Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
        Dim loginUser As New clsLoginUser

        If txtUser.Text.Trim = "" Then

            MsgBox(getMsgStr("MSG00002", lblUser.Text))
            txtUser.Focus()
            Exit Sub
        End If

        'スキャンしたUserNoをDBにInsert or Update
        loginUser.insUser(g_CURRENT_EQUIP_ID, txtUser.Text)

        txtOptNoEnd.Text = txtUser.Text
        txtOptNoStt.Text = txtOptNoEnd.Text

        Time_LoginUser.Start()
        pnlUserLogin.Visible = False

    End Sub

    Private Sub btnManual_Click(sender As Object, e As EventArgs) Handles btnManual.Click
        If IsNothing(m_cEquipCommandControl) = False Then
            m_cEquipCommandControl.CommandDisConnect()
        End If
        Me.Close()
        frmStartCompletePlateCheck.ShowDialog()
    End Sub

    Private Sub btnOptNoStt_Click(sender As Object, e As EventArgs) Handles btnOptNoStt.Click, btnOptNoEnd.Click
        Time_LoginUser.Stop()
        pnlUserLogin.Visible = True
        Me.pnlUserLogin.BringToFront()
        txtUser.Select()
        Exit Sub
    End Sub

    Private Sub btnDel_Click(sender As Object, e As EventArgs) Handles btnDel.Click
        If dgv.SelectedRows.Count > 0 Then

            Dim _lotNo As String = dgv.SelectedRows(0).Cells(0).Value

            If MsgBox("确定要删除组立Lot：" & _lotNo & " 吗？", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then

                If objAP.delete(_lotNo) = 1 Then
                    setDataGridView()
                Else
                    setCheckInfo("删除失败！")
                End If
            End If
        End If
    End Sub

    Private Sub btnErrInput_Click(sender As Object, e As EventArgs) Handles btnErrInput.Click
        Dim dtErr As DataTable
        Dim objLotDefect As New clsDbLotDefect
        If txtLotNo.Text = "" Then Exit Sub
        Dim frmErrInput As New frmLotCategoryInput
        frmErrInput.LotNo = txtLotNo.Text
        frmErrInput.EquipID = g_CURRENT_EQUIP_ID 'UPD 苗 2018/1/19 装置No.の対応
        frmErrInput.KouteiCD = lblProcCD.Text
        'frmErrInput.ErrorTable = dtError
        frmErrInput.StartPosition = FormStartPosition.CenterScreen
        frmErrInput.preProcCompleteCnt = CInt(lblInputCnt.Text)
        frmErrInput.ShowDialog()
        dtErr = objLotDefect.GetDefectData(txtLotNo.Text, g_CURRENT_EQUIP_ID, lblProcCD.Text)

        lblCompleteCnt.Text = CInt(lblInputCnt.Text)
        lblPcbCnt.Text = lblInputFrm.Text
        lblCrossCnt.Text = lblInputCross.Text
        lblCrossPcbCnt.Text = lblInputCrossFrm.Text

        If IsNothing(dtErr) = False AndAlso dtErr.Rows.Count > 0 Then
            Dim _errCount As Integer = 0
            For Each dr As DataRow In dtErr.Rows
                _errCount = dr(2) + _errCount
            Next
            lblFailedCnt.Text = _errCount
        End If

        lblCompleteCnt.Text = CInt(lblInputCnt.Text) - CInt(lblFailedCnt.Text)
        lblCrossCnt.Text = CInt(lblCrossCnt.Text) + CInt(lblFailedCnt.Text)
        If Not IsNothing(WG_IcTag) Then
            WG_IcTag.iFailed = CInt(lblFailedCnt.Text)
            WG_IcTag.iFinish = CInt(lblCompleteCnt.Text)
        End If
    End Sub

    Private Sub btnCheckInfoClose_Click(sender As Object, e As EventArgs) Handles btnCheckInfoClose.Click
        txtChkInfo.Text = ""
        pnlCheckInfo.Visible = False
    End Sub

    Private Sub dgv_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgv.CellClick
        If (e.RowIndex > -1) Then
            Dim _lotNo As String = dgv.Rows(e.RowIndex).Cells(0).Value.ToString()
            Dim _rackNo As String = dgv.Rows(e.RowIndex).Cells(1).Value.ToString()

            If SyncLotInfoBsite(_lotNo, _rackNo, IcTag) <> 0 Then
                setCheckInfo("bSite中不存在此Lot：" & _lotNo)
            End If
        End If
    End Sub
    Protected Sub setHeader(_type As String, ByVal szBeginTime As String, Optional ByVal tagData As frmStartCompleteBase.TagData = Nothing)

        m_dtHeader = m_cEquipMat.GetHeader(tagData.szLotNo, g_EQUIP_NO, tagData.szProcsCD, DateTime.Now.ToString(DATE_TIME_FORMAT_DB)) 'UPD 苗 2018/1/19 装置No.の対応
        If m_dtHeader.Rows.Count <= 0 Then
            m_dtHeader.Rows.Add()
        End If

        With m_dtHeader.Rows(0)
            .Item("LOT_NO") = tagData.szLotNo
            .Item("KOUTEI_CD") = tagData.szProcsCD
            .Item("TYPE") = _type
            .Item("OPERATOR") = txtOptNoStt.Text
            .Item("EQUIP_ID") = g_EQUIP_NO 'UPD 苗 2018/1/19 装置No.の対応
            .Item("PROD_NAME") = lblkindNm.Text
            .Item("DIFF_LOT") = lblDiffLotNo.Text
            .Item("PB_LAYOUT") = lblPbLayout.Text
            .Item("SHAPE") = lblShape.Text
            .Item("BEGIN_TIME") = szBeginTime
            .Item("BEGIN_OPT") = txtOptNoStt.Text
            .Item("INPUT_QTY") = IcTag.iInput.ToString
            '>>20180302 大賀 GroupKey入力時ウェハ枚数入力

            .Item("INPUTFRM_QTY") = IcTag.iFrame.ToString

            '<<20180302 大賀 GroupKey入力時ウェハ枚数入力
            .Item("INPUTCROSS_QTY") = IcTag.iCross

            .Item("CROSS_QTY") = lblCrossCnt.Text 'ADD 苗 2018/1/17
            .Item("CROSS_FRMQTY") = lblCrossPcbCnt.Text 'ADD 苗 2018/1/17

            '>>20180111 兪
            If IsNothing(tagData.szLotNo) Then 'UPD 苗 2018/1/24 tagDataの値が無くても、Nothingではない
                .Item("COMPLETE_QTY") = lblCompleteCnt.Text
                .Item("DEFECT_QTY") = lblFailedCnt.Text
                '>>20180302 大賀 GroupKey入力時ウェハ枚数入力

                .Item("FRAME_QTY") = lblPcbCnt.Text

            Else
                .Item("COMPLETE_QTY") = tagData.iFinish
                .Item("DEFECT_QTY") = tagData.iFailed
                .Item("FRAME_QTY") = tagData.iFrame

                .Item("IS_CHECKED") = tagData.fCheckflag
                .Item("Q_FLAG") = tagData.fQflag
            End If

        End With

    End Sub

#End Region

End Class

Public Class cmd_ZG
    Public ID As String
    Public rackNo As String
End Class
Public Class cmd_ZR
    Public ID As String
    Public rackNo As String
    Public result As String
    Public errorNo As String
End Class
Public Class cmd_ZW
    Public ID As String
    Public rackNo As String
    Public result As String
    Public errorNo As String
End Class
Public Class cmd_WG
    Public ID As String
    Public rackNo As String
    Public result As String
    Public PL1A1 As Integer '框架变形
    Public PL1B1 As Integer '异物附着
    Public PL1C1 As Integer '电镀变色
    Public PL1D1 As Integer '电镀脏污
    Public PL1E1 As Integer '异常析出
    Public PL1F1 As Integer '电镀毛刺
    Public PL1G1 As Integer '溢料残留
    Public PL1H1 As Integer '未电镀
    Public PL1I1 As Integer '其他

End Class
Public Class cmd_WW
    Public ID As String
    Public rackNo As String
    Public result As String
    Public errorNo As String
End Class
Public Class cmd_ZN
    Public ID As String    'ZN
    Public inputNum As String '投入数
    Public OKnum As String '良品数
    Public NGnum As String '不良数
    Public FrameNum As String '框架数
    Public ProcCD As String '工程号
    Public CarFlg As String '车品
    Public PKG As String 'PKG名
    Public Status As String 'LOT状态

End Class